package com.hwadee.ems.config;

import jakarta.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.hwadee.ems.interceptor.LoginInterceptor;
import com.hwadee.ems.interceptor.RefreshTokenInterceptor;

import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

// import com.hwadee.ems.interceptor.LoginInterceptor;
// import com.hwadee.ems.interceptor.RefreshTokenInterceptor;

/**
 * @author EnosElinsa
 * @since 2024/06/19
 */
@Configuration
@ConditionalOnClass(DispatcherServlet.class)
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate srt;
    
    @SuppressWarnings("null")
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new RefreshTokenInterceptor(srt))
                .addPathPatterns("/**")
                .order(0);

        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                    "/user/login",
                    "/file/download/**"
                )
                .order(1);
    }

}
